package com.boarsoft.message.rabbitmq;

import java.io.IOException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.springframework.amqp.core.Address;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.support.converter.MessageConversionException;
import org.springframework.amqp.support.converter.MessageConverter;

import com.boarsoft.message.bean.RecipientStatus;
import com.boarsoft.serialize.ObjectSerializer;

public class AmqpMsgConverter implements MessageConverter {
	protected ObjectSerializer serializer;

	@Override
	public Message toMessage(Object o, MessageProperties props) throws MessageConversionException {
		if (o instanceof com.boarsoft.message.bean.Message) {
			com.boarsoft.message.bean.Message m = (com.boarsoft.message.bean.Message) o;
			props.setMessageId(m.getId());
			props.setConsumerQueue(m.getTarget());
			props.setReplyTo(m.getFrom());
			props.setReplyToAddress(new Address(m.getFromAddr()));
			// TODO 填充其它信息
			o = m.getContent();
		}
		try {
			byte[] ba = serializer.serialize(o);
			return new Message(ba, props);
		} catch (IOException e) {
			throw new MessageConversionException(e.getMessage(), e);
		}
	}

	@Override
	public Object fromMessage(Message message) throws MessageConversionException {
		// TODO Auto-generated method stub
		return null;
	}

}
